﻿using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;

namespace MinaspetroLibrary.BoletoPack
{
    public class BoletoChildInfo : Csla.ReadOnlyBase<BoletoChildInfo>
    {
        #region Business Properties and Methods

        private Guid _id = Guid.NewGuid();

        private int _idSeq = 0;
        
        private string _cnpj = string.Empty;
        
        private double _valor = 0;

        private DateTime _data = DateTime.Now;

        private string _numDocumento = string.Empty;

        private string _razaoSocial = string.Empty;
        
        private string _endereco = string.Empty;
        
        private string _bairro = string.Empty;
        
        private string _cep = string.Empty;
        
        private string _cidade = string.Empty;
        
        private string _estado = string.Empty;

        private DateTime _dataGerBoleto = DateTime.Now;

        [System.ComponentModel.DataObjectField(true, true)]
        public Guid Id
        {
            get
            {
                return _id;
            }
        }

        public string Cnpj
        {
            get
            {
                return _cnpj;
            }
        }

        public double Valor
        {
            get
            {
                return _valor;
            }
        }

        public string ValorFormatado
        {
            get
            {
                return _valor.ToString("###,###,##0.00");
            }
        }

        public DateTime Data
        {
            get
            {
                return _data;
            }
        }

        public string DataShortString
        {
            get
            {
                return _data.ToString("dd/MM/yyyy");
            }
        }

        public string DataFullString
        {
            get
            {
                return _data.ToString("dd/MM/yyyy HH:mm");
            }
        }


        public string NumDocumento
        {
            get
            {
                return _numDocumento;
            }
        }

        public string RazaoSocial
        {
            get
            {
                return _razaoSocial;
            }
        }

        public string Endereco
        {
            get
            {
                return _endereco;
            }
        }

        public string Bairro
        {
            get
            {
                return _bairro;
            }
        }

        public string Cep
        {
            get
            {
                return _cep;
            }
        }

        public string Cidade
        {
            get
            {
                return _cidade;
            }
        }

        public string Estado
        {
            get
            {
                return _estado;
            }
        }

        public string DataGerBoleto
        {
            get
            {
                return _estado;
            }
        }


        protected override object GetIdValue()
        {
            return _id.ToString();
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in BoletoChildInfo

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static BoletoChildInfo GetBoletoChildInfo(SafeDataReader dr)
        {
            return new BoletoChildInfo(dr);
        }

        private BoletoChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods

        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _idSeq = dr.GetInt32("IdSeq");
            _id = new Guid(dr["Id"].ToString());
            _cnpj = dr.GetString("Cnpj");
            _valor = dr.GetDouble("Valor");
            _data = dr.GetDateTime("Data");
            _numDocumento = dr.GetString("NumDocumento");
            _razaoSocial = dr.GetString("RazaoSocial");
            _endereco = dr.GetString("Endereco");
            _bairro = dr.GetString("Bairro");
            _cep = dr.GetString("Cep");
            _cidade = dr.GetString("Cidade");
            _estado = dr.GetString("Estado");
            _dataGerBoleto = dr.GetDateTime("DataGerBoleto");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
